<template>
  <div  class="wrapper">
    <div style="height:300px">
      <FormPanel  
        ref="from"
        :list="initForm"   
        :cols="3"   
        :formType="value.type"
        :labelWidth="120"
        :isSubmitBtn="false"
        :collapse="false"
        @formChange="changeHandle"
      />
    </div>
    <div class="dialogBottmView">
      <el-button @click="closeDialog('closeDialog')">返 回</el-button>
      <el-button :loading="loadingFlag" @click="saveDialog()" type="primary">保 存</el-button>
    </div>
  </div>
</template>    

<script>
import { updateDict } from '@/api/partsmanage/partinfos/partParameter';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'chaimeffectivenessinfo',
  mixins: [dictionary],
  props:{
    value: {
      type: Object,
      data: Object,
      required: true
    },
  },
  data() {
    return {
      initForm : this.initFormFun(),
      loadingFlag: false
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.initForm.forEach(x => {
        x.initialValue = Number(this.value.data[x.fieldName]);
      });
    },
    initFormFun(){
      return [
        {
          type: 'SELECT',
          label: '索赔类型',
          fieldName: 'name',
          placeholder: '请选择',
          initialValue: "",
          disabled: true,
          itemList: this.createDictList('5006'),
          rules: [{
            required: true,
            message: '必填',
            trigger: 'change'
          }]
        },
        {
          type: 'INPUT_NUMBER',
          label: '索赔时效(天)',
          fieldName: 'value',
          placeholder: '请输入',
          initialValue: '',
          style: { width: '120px' },
          descOptions: {
            content: '天'
          },
          rules: [
            { required: true, message: '必填', trigger: 'blur' },
            { required: true, pattern: /^([1-9]\d{0,2}|999)$/, message: '请输入正整数(最大三位)' }
          ]
        }
      ]
    },
    changeHandle(val){
      this.saveData=val
    },
    closeDialog(type) {
      this.$emit('close', {visible: false, type: type});
    },
    async saveDialog() {
      this.$refs.from.SUBMIT_FORM();
      if (this.saveData) {
        this.saveData.id = this.value.data.id
        this.loadingFlag = true;
        let res=await updateDict(this.saveData)
        if (res.resultCode === 200) {
          this.$notify.success({title: '提示信息',message:'保存成功!'});
          this.loadingFlag = false;
          this.closeDialog('refresh')
        } else {
          this.$notify.error({title: '提示信息',message:res.errMsg||'保存失败!'});
        }
      }
    }
  }
}
</script>